package com.magicsoft.share.presenter.share;

import com.magicsoft.share.base.BasePresenter;
import com.magicsoft.share.bean.my.MessageRead;
import com.magicsoft.share.bean.share.ArticleType;
import com.magicsoft.share.constant.APIService;
import com.magicsoft.share.constant.SPKey;
import com.magicsoft.share.rx_retrofit_network.location.retrofit.RetrofitUtil;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.NetWorkTransformer;
import com.magicsoft.share.rx_retrofit_network.location.rxandroid.SimpleObserver;
import com.magicsoft.share.utils.SPUtils;
import com.magicsoft.share.view.share.IShareView;

import java.util.List;

import io.reactivex.annotations.NonNull;

/**
 * Created by lyf on 2017/11/24/024.
 */

public class SharePresenter extends BasePresenter<IShareView> {
    public void articleTypeList(){
        RetrofitUtil.getApi(APIService.class)
                .articleTypeList()
                .compose(new NetWorkTransformer<List<ArticleType>>())
             //   .compose(new LoadingTransformer<List<ArticleType>>(mContext))
                .subscribe(new SimpleObserver<List<ArticleType>>(mCompositeDisposable) {
                    @Override
                    public void call(@NonNull List<ArticleType> articleTypes) {

                        getView().articleTypeListSuccess(articleTypes);
                    }
                });
    }

    public void messageRead() {

        RetrofitUtil.getApi(APIService.class)
                .messageRead(SPUtils.getInstance().getString(SPKey.TOKEN), SPUtils.getInstance().getLong(SPKey.ID))
                .compose(new NetWorkTransformer<MessageRead>())
          //      .compose(new LoadingTransformer<MessageRead>(mContext))
                .subscribe(new SimpleObserver<MessageRead>(mCompositeDisposable) {
                    @Override
                    public void call(MessageRead messageRead) {

                        getView().messageRead(messageRead);
                    }
                });
    }

    public void checkLogin() {
        RetrofitUtil.getApi(APIService.class)
                .checkLogin(SPUtils.getInstance().getLong(SPKey.ID))
                .compose(new NetWorkTransformer())
                .subscribe(new SimpleObserver(mCompositeDisposable) {
                    @Override
                    public void call(@NonNull Object o) {

                    }
                });
    }
}
